Test Series - java script

Test Number 84/92

Q: Which handler is triggered when the content of the document in the window is stable and ready for manipulation?
A. onload
B. manipulate
C. create
D. oncreate
Solution: One of the most important event handlers is the onload handler of the Window object. It is triggered when the content of the document displayed in the window is stable and ready to be manipulated. JavaScript code is commonly wrapped within an onload event handler.
Q: Where are memory leaks found?
A. Client side objects
B. Server side objects
C. Both Client side and Server side objects
D. User side objects
Solution: Memory leaks happen when your code needs to consume memory in your application, which should be released after a given task is completed but isn’t. Memory leaks occur when we are developing client-side reusable scripting objects.
Q: What is the central concept of JavaScript memory management?
A. Reliability
B. Reachability
C. Efficiency
D. Transparency
Solution: The central concept of JavaScript memory management is a concept of reachability. The main cause for leaks in garbage collected languages are unwanted references.
A distinguished set of objects are assumed to be reachable: these are known as the roots. Typically, these include all the objects referenced from anywhere in the call stack (that is, all local variables and parameters in the functions currently being invoked), and any global variables.
Objects are kept in memory while they are accessible from roots through a reference or a chain of references.
Q: When does a memory leak happen?
A. Browser doesn’t release memory from objects unnecessary
B. Browser releases too many memories
C. Browser releases memory iteratively
D. Browser releases memory quickly
Solution: Memory leaks happen when your code needs to consume memory in your application, which should be released after a given task is complete but isn’t. Memory leak happens when the browser for some reason doesn’t release memory from objects which are not needed any more.
Q: What will happen when the data of the jQuery.cache is read from an element?
A. Unique number is retrieved as elem[jQuery.expando]
B. Data is read from jQuery.cache[id]
C. Unique number is retrieved as elem[jQuery.expando] & Data is read from jQuery.cache[id]
D. Data is cleared from jQuery.cache[id]
Solution: jQuery.cache[id] is used to associate handlers and other data with elements. When the data is read from an element:
The element unique number is retrieved from id = elem[ jQuery.expando].
The data is read from jQuery.cache[id].
Q: The style property belongs to which of the following object?
A. Element
B. Window
C. Location
D. Navigation
Solution: Each Element object has style and className properties that allow scripts to specify CSS styles for a document element or to alter the CSS class names that apply to the element.
Q: Which of the following functions are referenced internally?
A. setTimeout
B. setInterval
C. both setTimeout and setInterval
D. clearInterval
Solution: setTimeout(function, milliseconds) executes a function, after waiting a specified number of milliseconds. Functions used in setTimeout/setInterval are referenced internally and tracked until complete, then cleaned up.
Q: What is the purpose of destroying the functions and objects?
A. Consume unnecessary CPU cycles
B. Prevent the dropping of reference count to 0
C. Centralize the responsibility to clean up
D. All of the mentioned
Solution: The primary purpose of a destroy function is to centralize the responsibility for cleaning up anything that the object has done that will:
Prevent its reference count from dropping to 0 (for example, removing problematic event listeners and callbacks and unregistering from any services).
Consume unnecessary CPU cycles, such as intervals or animations.
Q: When does a cycle occur during memory leak?
A. No reference occurs
B. Two objects reference
C. One object gets referenced
D. Three object gets referenced
Solution: Old versions of Internet Explorer could not detect cyclic references between DOM nodes and JavaScript code. A cycle happens when two objects reference each other in such a way that both objects retain each other.
Q:  Which of the following is a way to retain an object in memory?
A. Console Log
B. Closures
C. Destroy objects
D. Clear object
Solution: Any object inside the timer will hold a reference in order to run that piece of code somewhere in the future without any problems. One particularly obscure way to retain an object in memory is to log it to the console.

You Have Score    /10